<?php
	class order extends common{

		  //订单交易状态
	    var $trading_status = array(
	        1 => '进行中' , 2 => '成功' , 3 => '失败' , 4 => '申请退款' , 5=> '待退款'
	        );
	    //支付状态
	    var $pay_status = array(
	        1 => '待支付' , 2 => '已支付' , 3 => '到账' , 4 => '退款成功' , 5 => '交易完成'
	        );
	    //支付类型
	    var $pay_style = array(0=>'未选择',1 => '微信' , 2 => '支付宝' , 3 => '银联'); 

		var $table = 'company_order';
		
		function __construct($pagec){
			parent::__construct($pagec);
		}
		
		/**
		 * 订单列表
		 * @param  string  $where 
		 * @param  string  $key   
		 * @param  integer $page  0 不分页
		 * @return aray         
		 */
		function orderList($where , $key= 'o.*' , $page = 0){
			$sql = $this->table . ' o LEFT JOIN company_product p ON o.product_id=p.id 
				LEFT JOIN users u ON o.user_id = u.id 
				LEFT JOIN companies c ON o.company_id = c.id 
				WHERE 1=1 ' . $where;
			$key .= ' , p.name as product_name , c.title as company_name,u.userName';
			$sqlnum = $page == 0 ? '' : $sql;
			$res = $this->getList($sql, $sqlnum, $key,$debug='0');
			if(is_array($res['result'])){
				foreach($res['result'] as $k => $v){
					$res['result'][$k]['payStatus'] = $this->pay_status[$v['pay_status']];
					$res['result'][$k]['payStyle'] = $this->pay_style[$v['pay_style']];
					$res['result'][$k]['tradingStatus'] = $this->trading_status[$v['trading_status']];
				}
			}
			return $res;
		}

		/**
		 * 订单详情
		 * @param  string $where
		 * @param  string $key 
		 * @var string
		 */
		function orderInfo($where , $key = 'o.*'){
			$info = $this->orderList($where , $key);
			return $info['result'][0];
		}

		/**
		 * 订单更新
		 * @param  array $arr   
		 * @param  string $where 
		 * @return bool        
		 */
		function orderUpdate($arr , $where){
			$res = $this->update($this->table , $arr , $where);
			return $res;
		}

		/**
		 * 退款申请详情
		 * @param  [type] $id         
		 * @param  string $key        
		 * @param  string $search_key 
		 * @return [type]             
		 */
		function refundInfo($id , $key = '*' , $search_key = 'id'){
			$table = 'company_refund';
			$info = $this->getInfo($table , $id , $key , $search_key);
			return $info;
		}

		/**
		 * 退款更新
		 * @param  array $arr   
		 * @param  string $where 
		 * @return bool        
		 */
		function refundUpdate($arr , $where){
			$table = 'company_refund';
			$res = $this->update($table , $arr , $where);
			return $res;
		}
		
	}
?>